<extend name="./public/frame.html"/>
<block name="content">
    <blockquote class="layui-elem-quote search">
        <div class="layui-inline">
            <input type="text" name="title" lay-verify="required|title" required placeholder="请输入车牌号"
                   class="layui-input" id="car_plate">
        </div>
        <div class="layui-inline">
            <input type="text" name="title" lay-verify="required|title" required placeholder="请输入手机号"
                   class="layui-input" id="driver_phone">
        </div>
        <div class="layui-inline">
            <select name="province_id" id="province_id" class="layui-input" lay-filter="province" style="width: 150px;" onclick="getProvinceList();">
                <option value="">请选择认证省份</option>
                <?php foreach($provinceList as $key=>$value):?>
                <option value="<?php echo $value['region_id'];?>"><?php echo $value['region_name'];?></option>
                <?php endforeach;?>
            </select>
        </div>
        <div class="layui-inline">
            <select name="city_id" id="city_id" class="layui-input" lay-filter="city_id" style="width: 150px;">
                <option value="">请选择认证城市</option>
            </select>
        </div>
        <div class="layui-inline">
            <button class="layui-btn" data-type="search">搜索</button>
        </div>
    </blockquote>

    <table class="layui-table" lay-filter="authT" id="authT"></table>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        {{#if(d.record_status == 2){ }}
        <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="auth">待审核</a>
        {{#}else{ }}
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="auth">未通过</a>
        {{#} }}
        {{#if(d.backStatus == 2){ }}
        <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="driverBack" href="javascript:void(0)">查询成功</a>
        {{#}else{ }}
        <a class="layui-btn layui-btn-xs" lay-event="driverBack" onclick="driverDataCheck('{{d.driver_id}}','{{d.driver_name}}','{{d.id_number}}')">背调查询</a>
        {{#} }}

        {{#if(d.car_vin != 0 && d.code != 200 && d.record_status != 1){ }}
        <!--<a class="layui-btn layui-btn-xs" lay-event="driverBack" onclick="driverCarCheck('{{d.car_id}}','{{d.car_vin}}')">车险背调</a>-->
        {{#}else{ }}
        {{#if(d.car_vin != 0 && d.code == 200){ }}
        <!--<a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="driverBack" href="javascript:void(0)">车险成功</a>-->
        {{#} }}
        {{#} }}
    </script>

    <script>
        layui.use(['table'],function () {
            var table = layui.table;
            var tableIns = table.render({
                elem:"#authT",
                url:"{:U('index')}",
                where:{driver_type : "{$driver_type}"},
                cols: [[
                    {title:"车辆ID",field:'car_id', width:80,align:'center'},
                    {title:"司机ID",field:'driver_id', width:80,align:'center'},
                    {title:"姓名",field:'driver_name', width:100,align:'center'},
                    {title:"手机号",field:'driver_phone', width:120,align:'center'},
                    //{title:"认证类型",field:'auth_type', width:120,align:'center'},
                    {title:"第几辆车",field:'car_number', width:120,align:'center'},
                    {title:"车牌号",field:'car_plate', width:120,align:'center'},
                    /*{title:"车辆品牌",field:'car_brand', width:120},
                    {title:"车辆型号",field:'car_model', width:120},
                    {title:"颜色",field:'color', width:80,sort:true},*/
                    {title:"车辆注册时间",field:'register_at', width:120,align:'center'},
                    {title:"申请认证时间",field:'add_time', width:120,align:'center'},
                    /*{title:"注册城市",field:'register_city', width:220},*/
                    {title:"认证省",field:'region_name_province', width:100,align:'center'},
                    {title:"认证市",field:'region_name_city', width:100,align:'center'},
                    {title:"认证失败原因",field:'reason', width:220,align:'center'},
                    {title:"操作",toolbar: '#barDemo',width:270,fixed:'right',align:'center'}
                ]],
                page:true,
                limit:10
            });
            //监听工具条
            table.on('tool(authT)', function (obj) {
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                var car_id = data.car_id;
                if(layEvent === 'edit'){
                    layer.open({
                        type: 2,
                        title: '车主信息编辑',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['100%', '100%'],
                        content:'{:U("edit","car_id=")}' + car_id
                    });
                }else if(layEvent === 'auth'){
                    layer.open({
                        type: 2,
                        title: '车主信息审核',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['100%', '100%'],
                        content:'{:U("auth","car_id=")}'+car_id,
                    });
                }
            });
            var $ = layui.jquery, active = {
                search: function () {
                    var car_plate = $.trim($('#car_plate').val());
                    var driver_phone = $.trim($('#driver_phone').val());
                    var province_id = $("#province_id").val();
                    var city_id = $("#city_id").val();
                    var driver_type = "{$driver_type}";
                    if(car_plate||driver_phone||province_id||city_id){
                        tableIns.reload({
                            url: "{:U('index')}",
                            where: {
                                car_plate : car_plate,
                                driver_phone : driver_phone,
                                province_id : province_id,
                                city_id : city_id,
                                driver_type : driver_type
                            } //设定异步数据接口的额外参数
                        });
                    }else{
                        layer.alert('搜索项不能为空');
                    }
                }
            };
            $('.layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
        });
        function driverDataCheck(driver_id,driver_name,id_number) {
            var loading = layer.load(1, {
                shade: [0.5, '#000'],
                content:'<div style="width: 500px;height: 40px;line-height: 40px;padding-left: 42px;font-size:16px;">数据查询中.....请稍后</div>',
                time:20*1000
            });
            $.ajax({
                url:"{:U('driverDataCheck')}",
                async:true,
                dataType:'json',
                type:'POST',
                data:{'name':driver_name,'id_number':id_number,'driver_id':driver_id},
                success:function(res){
                    if(res.code==1){
                        //$("#driverInfo").html(res.itemPropLabel);
                        //$("#driverInfoTime").html(res.driverInfoTime);
                        layer.msg(res.msg,{icon: 6});
                        setTimeout(function (){
                            window.location.reload();
                        }, 2000);
                    }else{
                        layer.msg(res.msg,{icon: 5});
                    }
                    layer.close(loading);
                }
            });
        }
        function getProvinceList(){
            $("#city_id").empty();
            $("#city_id").append('<option value=>请选择认证城市</option>');
            var province_id = $("#province_id").val();
            $.ajax({
                url:'{:url("/admin/Franchisee/cityList")}',
                async:true,
                //dataType:'json',
                type:'post',
                data:{'province_id':province_id},
                success:function(res){
                    $("#city_id").append(res);
                },
                error:function(e){
                    layer.msg('请求错误');return false;
                }
            })
        };
    </script>
</block>
